package com.jn.algorithm.day001.question2;

/**
 * @author 江南大学1033190417
 * @date 2022/4/15 10:36
 */
public class Solution {
    public ListNode addTwoNumbers(ListNode l1, ListNode l2) {

        StringBuilder num1 = new StringBuilder();
        StringBuilder num2 = new StringBuilder();
        while (l1 != null) {
            num1.insert(0, l1.val);
            l1 = l1.next;
        }
        while (l2 != null) {
            num2.insert(0, l2.val);
            l2 = l2.next;
        }
        String count = String.valueOf(Integer.parseInt(num1.toString()) + Integer.parseInt(num2.toString()));
        ListNode result = new ListNode();
        ListNode temp = result;
        System.out.println(result.hashCode()==temp.hashCode());
        for (int i = count.length() - 1; i >= 0; i--) {
            temp.val = Integer.parseInt(String.valueOf(count.charAt(i)));
            if (i-1 >= 0) {
                temp.next = new ListNode();
                temp = temp.next;
            }
        }
        return result;
    }

    public static void main(String[] args) {
        ListNode l1 = new ListNode();
        l1.val = 9;

        ListNode l2 = new ListNode();
        l2.val = 9;
        l2.next = new ListNode(4);
        l2.next.next = new ListNode(4);
        l2.next.next.next = new ListNode(6);
        l2.next.next.next.next = new ListNode(1);
        l2.next.next.next.next.next = new ListNode(1);
//        l2.next.next.next.next.next.next = new ListNode(9);
//        l2.next.next.next.next.next.next.next = new ListNode(9);
//        l2.next.next.next.next.next.next.next.next = new ListNode(9);
//        l2.next.next.next.next.next.next.next.next.next = new ListNode(1);

        Solution solution=new Solution();
        solution.addTwoNumbers(l1,l2);
        while (l2 != null) {
            System.out.println(l2.val);
            l2 = l2.next;
        }
    }
}

class ListNode {
    int val;
    ListNode next;

    ListNode() {
    }

    ListNode(int val) {
        this.val = val;
    }

    ListNode(int val, ListNode next) {
        this.val = val;
        this.next = next;
    }
}